
global user "`c(username)'"
global dirdata "C:\Users\\$user\Dropbox\CCT BJP\data"
global dir1 "$dirdata\Final data"
global dir2 "$dirdata\Results\graphs"
global dir3 "$dirdata\Results\"
cd "$dir3"
set matsize 10000
use "$dir1\pooled_hh.dta", clear
keep if tau>-5  
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1
replace schooling_p=. if work_p==.
g Post=tau>=0
sum age_sac
global covs " age_sac c.age_sac#i.year i.year"


 
local spec1 Post i.min_schooling $covs  
local sample3 "(min_schooling>=1 & min_schooling<9)  "

local replace replace
foreach x in  np urban age age_m age_p spanish spanish_m spanish_p schooling schooling_m schooling_p {
sum `x' if tau==-1 & `sample3' 
local mean_dv=r(mean)
areg `x'  `spec1' [w=factor] if `sample3' , a(departamento) cluster(municipio)
outreg2 using "$dir3\Sorting", excel `replace' ctitle(``x'_lab') keep(Post) less(0) nocons  bdec(3) adds(Clusters, e(N_clust), Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Sample, 1st-8th, Group linear trends, YES, Region X year FE, NO)
test Post
local replace append
}
est clear
**** F Test for joint significance:


foreach x in  np age age_m age_p spanish spanish_m spanish_p schooling schooling_m schooling_p urban {
reg `x' `spec1' [w=factor] if `sample3' 
est sto `x' 
}
quietly suest  np age age_m age_p spanish spanish_m spanish_p schooling schooling_m schooling_p urban , cluster(municipio)

test Post
